﻿using System;
using Kingzad.MicroService.BusinessCore.Models.Options;
using Microsoft.Extensions.Options;
using MongoDB.Driver;

namespace Kingzad.MicroService.BusinessCore.Providers
{
    public interface IMongoConnectionFactory
    {
        IMongoDatabase GetConnection();
    }
    public class MongoConnectionFactory : IMongoConnectionFactory
    {
        private readonly IOptions<Connections> _connections;

        public MongoConnectionFactory(IOptions<Connections> connections)
        {
            _connections = connections;
        }

        public IMongoDatabase GetConnection()
        {
            var _client = new MongoClient(_connections.Value.MongoConnection);
            return _client.GetDatabase(_connections.Value.MongoDBName);
        }
    }
}
